﻿@page
@model _17bang.Pages.Task.History.MonthModel
<link rel="stylesheet" href="lib/bootstrap/dist/css/bootstrap.css" />

@*新建 /Task/History/Month 页面，利用表格，输出按月按周组织的任意一个月份的日历。可参考：一起帮·任务历史月表*@
@*1号是周一 开始七天一个循环  1号不是周一 往后退回到是周一的那天  开始七天一个循环*@

@{
    int year = 2010;
    int month = 1;
}
@functions{

    DateTime GetFirstMonday(int year, int month)
    {
        DateTime firstofday = new DateTime(year, month, 1);
        while (firstofday.DayOfWeek != DayOfWeek.Monday)
        {
            firstofday.AddDays(-1);
        }
        return firstofday;
    }
}
<div>
    <table class="table">
        <thead>
            <tr>
                <th scope="col">一</th>
                <th scope="col">二</th>
                <th scope="col">三</th>
                <th scope="col">四</th>
                <th scope="col">五</th>
                <th scope="col">六</th>
                <th scope="col">七</th>
            </tr>
        </thead>
        <tbody>
            <tr>
                <td>
                    @for (int i = 0; i < 43; i++)
                    {
                        if (i % 7 != 0)
                        {
                            DateTime start = GetFirstMonday(year, month).AddDays(1);
                            @start.ToString("yyyy年MM月dd日");
                        }
                        else
                        {
                            <br />
                        }
                    }
                </td>
            </tr>
        </tbody>
    </table>
</div>